<template>
	<view style="background: #FFFFFF; flex: 1; height: 100%;padding-left: 26rpx;">
		<view class="row-css" style="padding-top: 80rpx;font-size: 32rpx;color: #575858;text-align: center;">输入验证码,验证码已发送您的手机</view>
		<!-- <view class="row-css" style="padding-top: 30rpx;font-size: 32rpx;text-align: center;">{{ userphone }}</view> -->
		<view style=" padding-left: 20rpx;padding-top: 100rpx;"><valid-code type="bottom" :maxlength="6" @finish="finish"></valid-code></view>
		<view style="color:#00BFFF; margin-top: 100rpx;font-size: 32rpx; display: flex; flex:1; justify-content: center;align-items: center;" @click="sendcode">
			{{ codeText }}
		</view>
	</view>
</template>

<script>
import validCode from '../../components/valid-code/valid-code.vue';
export default {
	components: {
		validCode
	},
	data() {
		return {
			userphone: '13269856958',
			codeText: '重新获取验证码',
			payId: '',
			amount: '',
			otpOrderNo: '',
			businessNo: '',
			bankName: '',
			bankNo: '',
			messageOrderNo: '',
			ipAddr: '',
			// num: '',
			// num0: '',
			// num1: '',
			// num2: '',
			// num3: '',
			// num4: '',
			// num5: '',
			time: 60,
			category: false,
			iscode: 0
		};
	},
	// onLoad(e) {
	// 	if (e.userphone) {
	// 		this.userphone = e.userphone;
	// 	}
	// 	//开始获取验证码倒计时
	// 	this.recede();
	// },
	onLoad: function(options) {
		// withdrawdata.bankName = this.bankName;
		// withdrawdata.bankName = this.bankName;
		// withdrawdata.bankNo = this.accountNum;

		let withdrawdata = JSON.parse(options.withdrawdata);
		this.category = withdrawdata.category;
		this.payId = withdrawdata.payId;
		this.amount = withdrawdata.amount;
		this.otpOrderNo = withdrawdata.otpOrderNo;
		this.businessNo = withdrawdata.businessNo;

		this.bankName = withdrawdata.bankName;
		this.bankNo = withdrawdata.bankNo;
		this.messageOrderNo = withdrawdata.messageOrderNo;

		if (this.category == 'false') {
			uni.setNavigationBarTitle({
				title: '输入手机验证码（委托收款人)' //这是修改后的导航栏文字
			});
		}
		let that = this;
		that.wxRequest({
			// 获取ip
			url: `${that.API}/driverService/getIp`,
			success(res) {
				that.ipAddr = res.data.data.ip
			}
		});
		//开始获取验证码倒计时
		that.recede();
	},
	methods: {
		sendcode() {
			if (this.time > 0) {
				this.time--;
				uni.showToast({
					title: this.time + 's后重新获取',
					icon: 'none'
				});
			} else {
				this.time = 0;
				uni.showToast({
					title: '获取验证码',
					icon: 'none'
				});
				this.recede();
				if (this.category) {
					//二类户
					this.wxRequest({
						url: `${this.API}/mini/erLeiHu/getIdCodeByCash`,
						method: 'POST',
						data: {
							payId: this.payId,
							amount: this.amount
						},
						title: '验证码发送中...',
						success: res => {
							this.otpOrderNo = res.data.data.otpOrderNo;
							this.businessNo = res.data.data.businessNo;
						}
					});
				} else {
					//见证宝
					this.wxRequest({
						url: `${this.API}/mini/jzb/cashOutMsg`,
						method: 'POST',
						data: {
							bankNo: this.accountNum,
							cashAmount: this.amount
						},
						title: '提现验证码发送中...',
						success: res => {
							this.messageOrderNo = res.data.data.messageOrderNo;
						}
					});
				}
			}
		},
		recede() {
			this.timer = setInterval(() => {
				this.codeText = `${this.time}s后重新获取验证码`;
				this.time--;
				if (this.time < 0) {
					this.time = 60;
					this.codeText = '重新获取验证码';
					clearInterval(this.timer);
				}
			}, 1000);
		},
		finish: function(e) {
			console.log('d=======w======>', e);
			let that = this;
			that.wxRequest({
				// 获取ip
				url: `${that.API}/driverService/getIp`,
				success(res) {
					that.ipAddr = res.data.data.ip
				}
			});
			if (that.iscode == 0) {
				console.log('------------', that.category);
				if (that.category) {
					//二类户
					that.wxRequest({
						url: `${that.API}/mini/erLeiHu/cashOut`,
						method: 'POST',
						data: {
							payId: that.payId,
							bussinessNo: that.businessNo,
							amount: that.amount,
							ipAddr: that.ipAddr,
							otpOrderNo: that.otpOrderNo,
							otpValue: e
						},
						title: '提现中...',
						success: res => {
							let accountNo = res.data.data.accountNo;
							// uni.showModal({
							// 	title: '提示',
							// 	content: '提现成功',
							// 	success: function(res) {
							// 		if (res.confirm) {
							// 			console.log('用户点击确定');
							uni.redirectTo({
								url: '../personal/withdrawsuccessfully?category=' + that.category + '&bussinessNo=' + that.businessNo + '&accountNo=' + accountNo
							});
							// 		} else if (res.cancel) {
							// 			console.log('用户点击取消');
							// 		}
							// 	}
							// });
						},
						complete: res => {
							that.iscode = 0;
						}
					});
				} else {
					//见证宝
					that.wxRequest({
						url: `${that.API}/mini/jzb/cashOut`,
						method: 'POST',
						data: {
							bankName: that.bankName,
							bankNo: that.bankNo,
							cashAmount: that.amount,
							messageOrderNo: that.messageOrderNo,
							otpOrderNo: that.otpOrderNo,
							verifyCode: e
						},
						title: '提现中...',
						success: res => {
							let accountNo = res.data.data.billNo;
							uni.redirectTo({
								url: '../personal/withdrawsuccessfully?category=' + that.category + '&bankNo=' + that.bankNo + '&accountNo=' + accountNo + '&amount=' + that.amount
							});
						},
						complete: res => {
							that.iscode = 0;
						}
					});
				}
				that.iscode = 1;
			}
		}
	}
};
</script>

<style>
page {
	background: #ffffff;
}
/* 
input {
	caret-color: transparent;
} */
</style>
